package com.ghp.admin.handler;

import com.ghp.common.utils.WebResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ghp
 * @title 拦截器异常处理器
 * @description
 */
@Slf4j
public class InterceptorExceptionHandler implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
        // 异常处理逻辑
        log.error("拦截器发生异常 \n {}", e.getMessage());
        WebResponseUtils.renderString(response, e.getMessage());
        return new ModelAndView();
    }
}
